package com.samwoo.slot.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

public class MarginDividerItemDecoration extends RecyclerView.ItemDecoration {

    private int horizontalMargin;
    private int verticalMargin;

    public MarginDividerItemDecoration(Context context, int horizontalMarginInDp, int verticalMarginInDp) {
        this.horizontalMargin = dpToPx(context, horizontalMarginInDp);
        this.verticalMargin = dpToPx(context, verticalMarginInDp);
    }

    private int dpToPx(Context context, float dp) {
        return (int) (dp * context.getResources().getDisplayMetrics().density + 0.5f);
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        outRect.left = horizontalMargin / 2;
        outRect.right = horizontalMargin / 2;
        outRect.top = verticalMargin / 2;
        outRect.bottom = verticalMargin / 2;
    }
}

